using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson23Work : MonoBehaviour
{
    RaycastHit hit;
    private Transform t ;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        //if (Input.GetMouseButtonDown(0))
        //{
        //    Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),
        //    out hit,
        //    1000,
        //    1 << LayerMask.NameToLayer("Wall"));
        //    if (hit.collider != null)
        //    {
        //        GameObject obj = Instantiate(Resources.Load<GameObject>("Effect/1"));
        //        obj.transform.position = hit.point+0.3f*hit.normal;
        //        obj.transform.rotation = Quaternion.LookRotation(hit.normal);
        //        Destroy(obj,0.5f);

        //        obj = Instantiate(Resources.Load<GameObject>("Effect/2"));
        //        obj.transform.position = hit.point + 0.1f * hit.normal;
        //        obj.transform.rotation = Quaternion.LookRotation(hit.normal);
        //        Destroy(obj, 0.5f);
        //    }
        //}

        if (Input.GetMouseButtonDown(0))
        {
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 1000, 1 << LayerMask.NameToLayer("Monster"));
            t=hit.transform;
        }
        if (Input.GetMouseButton(0))
        {
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 1000, 1 << LayerMask.NameToLayer("Floor"));
            if (t != null)
            {
                t.position = hit.point+Vector3.up*0.5f;
            }
            
        }
        if (Input.GetMouseButtonDown(1))
        {
            t = null; 
        }
    }
}
